- page_title "待办事项"
- header_title "待办事项", dashboard_todos_path

.top-area
  %ul.nav-links
    - todo_pending_active = ('active' if params[:state].blank? || params[:state] == 'pending')
    %li{class: "todos-pending #{todo_pending_active}"}
      = link_to todos_filter_path(state: 'pending') do
        %span
          待办事项
        %span.badge
          = todos_pending_count
    - todo_done_active = ('active' if params[:state] == 'done')
    %li{class: "todos-done #{todo_done_active}"}
      = link_to todos_filter_path(state: 'done') do
        %span
          已完成
        %span.badge
          = todos_done_count

  .nav-controls
    - if @todos.any?(&:pending?)
      = link_to destroy_all_dashboard_todos_path(todos_filter_params), class: 'btn btn-loading js-todos-mark-all', method: :delete do
        标记全部完成
        = icon('spinner spin')

.todos-filters
  .row-content-block.second-block
    = form_tag todos_filter_path(without: [:project_id, :author_id, :type, :action_id]), method: :get, class: 'filter-form' do
      .filter-item.inline
        = select_tag('project_id', todo_projects_options,
          class: 'select2 trigger-submit', include_blank: true,
          data: {placeholder: '项目'})
      .filter-item.inline
        = users_select_tag(:author_id, selected: params[:author_id],
          placeholder: '作者', class: 'trigger-submit', any_user: "任何作者", first_user: true, current_user: true)
      .filter-item.inline
        = select_tag('type', todo_types_options,
          class: 'select2 trigger-submit', include_blank: true,
          data: {placeholder: '类型'})
      .filter-item.inline.actions-filter
        = select_tag('action_id', todo_actions_options,
          class: 'select2 trigger-submit', include_blank: true,
          data: {placeholder: '动作'})

.prepend-top-default
  - if @todos.any?
    .js-todos-options{ data: {per_page: @todos.limit_value, current_page: @todos.current_page, total_pages: @todos.total_pages} }
    - @todos.group_by(&:project).each do |group|
      .panel.panel-default.panel-small.js-todos-list
        - project = group[0]
        .panel-heading
          = link_to project.name_with_namespace, namespace_project_path(project.namespace, project)

        %ul.content-list.todos-list
          = render group[1]
    = paginate @todos, theme: "gitlab"
  - else
    .nothing-here-block 全部已完成！

:javascript
  new UsersSelect();

  $('form.filter-form').on('submit', function (event) {
    event.preventDefault();
    Turbolinks.visit(this.action + '&' + $(this).serialize());
  });
